-
Notifications
You must be signed in to change notification settings - Fork 630
Snowflake: Support CREATE VIEW myview IF NOT EXISTS
#1961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "\u201Ccreate-view-name-before-if-not-exists\u201D"
Snowflake: Support CREATE VIEW myview IF NOT EXISTS
#1961
Conversation
Box::new(BigQueryDialect {}), | ||
]); | ||
let _ = dialects.verified_stmt(sql); | ||
let sql = "CREATE VIEW v IF NOT EXISTS AS SELECT 1"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick look I couldn't find which dialects in practice support this syntax? Do you have a link to documentation for one such dialect?
related the MR not super sure it would be necessary to have this behavior covered by a flag and the parser can always look to accept CREATE VIEW IF NOT EXISTS v
, as well as the other syntax if its relevant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I couldn't find official documentation for this syntax, though we have confirmed it works in practice on Snowflake.
I'm happy to remove the dialect flag and update the parser to support both forms for all dialects. Let me know if you'd like me to proceed with that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah in that case I think we can remove the dialect flags, not sure that we need to support both forms if CREATE VIEW v IF NOT EXISTS
is not supported by any dialect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's supported in snowflake, but not officially documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah alright, in that case yeah I think we could skip the dialect methods entirely and let the parser accept either format if they show up? Also we can add a comment flagging that the second format is supported by snowflake but is undocumented
…, also added ability to write view name before if not exists in snowflake as it is implemented, replaced dialect of with trait functions
…t exists supported by snowflake
6f60343
to
46ce27f
Compare
// Many dialects support `OR ALTER` right after `CREATE`, but we don't (yet). | ||
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either. | ||
let allow_unquoted_hyphen = dialect_of!(self is BigQueryDialect); | ||
let name = self.parse_object_name(allow_unquoted_hyphen)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work to only put something like this line after we've parsed? name
let name_before_not_exists = !if_not_exists && self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let if_not_exists = if_not_exists || name_before_not_exists;
thinking if so that would let us avoid the if/else and mut
let sql: &'static str = "CREATE VIEW IF NOT EXISTS v AS SELECT 1"; | ||
let _ = all_dialects().verified_stmt(sql); | ||
let sql = "CREATE VIEW v IF NOT EXISTS AS SELECT 1"; | ||
let _ = all_dialects().verified_stmt(sql); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test case for CREATE VIEW IF NOT EXISTS AS SELECT 1
to verify how the parser behaves in that scenario?
src/ast/mod.rs
Outdated
@@ -3263,6 +3263,8 @@ pub enum Statement { | |||
materialized: bool, | |||
/// View name | |||
name: ObjectName, | |||
// Name IF NOT EXIST instead of IF NOT EXIST name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Name IF NOT EXIST instead of IF NOT EXIST name | |
/// If `if_not_exists` is true, this flag is set to true if the view name comes before the `IF NOT EXISTS` clause. | |
/// Example: | |
/// ```sql | |
/// CREATE VIEW myview IF NOT EXISTS AS SELECT 1` | |
/// ``` | |
/// Otherwise, the flag is set to false if the view name comes after the clause | |
/// Example: | |
/// ```sql | |
/// CREATE VIEW IF NOT EXISTS myview AS SELECT 1` | |
/// ``` |
we could say something descriptive like this?
CREATE VIEW myview IF NOT EXISTS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @etgarperets!
cc @alamb
…, also added ability to write view name before if not exists in snowflake as it is implemented, replaced dialect of with trait functions